/*
 * Copyright (c) 2013 Hai Bison
 *
 * See the file LICENSE at the root directory of this project for copying
 * permission.
 */

package com.haibison.android.logs;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;

/**
 * Global settings, stored in {@link SharedPreferences}.
 * 
 * @author Hai Bison
 * 
 */
public class Settings {

    /**
     * This is singleton class.
     */
    private Settings() {
    }// Settings()

    private static final String PKEY_MAX_LOG_RECORDS = "max_log_records";

    /**
     * Gets global {@link SharedPreferences}.
     * 
     * @param context
     *            the context.
     * @return {@link SharedPreferences}.
     */
    @SuppressLint("InlinedApi")
    public static SharedPreferences p(Context context) {
        /*
         * Always use application context.
         */
        return context.getApplicationContext().getSharedPreferences(
                Env.LIB_NAME + '.' + Env.UID + ".settings",
                Context.MODE_MULTI_PROCESS);
    }// p()

    /**
     * Sets max log records.
     * 
     * @param context
     *            the context.
     * @param max
     *            max log records.
     */
    public static void setMaxLogRecords(Context context, int max) {
        p(context).edit().putInt(PKEY_MAX_LOG_RECORDS, max).commit();
    }// setMaxLogRecords()

    /**
     * Gets max log records.
     * 
     * @param context
     *            the context.
     * @return max log records. Default is {@code 999}.
     */
    public static int getMaxLogRecords(Context context) {
        return p(context).getInt(PKEY_MAX_LOG_RECORDS, 999);
    }// getMaxLogRecords()

}
